package org.lq.his.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.taglibs.standard.lang.jstl.test.beans.PublicInterface2;
import org.lq.his.dao.MyoDao;
import org.lq.his.pojo.Myo;
import org.lq.his.service.MyoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/myo")
public class MyoController {
	@Resource
	private MyoService myoService;
	
	
	public void setMyoService(MyoService myoService) {
		this.myoService = myoService;
	}
	@RequestMapping("/myoIndex")
	public String myoIndex()throws Exception{
		return "myo/myoIndex";
	}
	@RequestMapping(value="/myoAdd",method=RequestMethod.GET)
	public String myoAdd()throws Exception{
		return "myo/myoForm";
	}
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit()throws Exception{
		return "myo/myoForm";
	}
	
	@RequestMapping("/list") 
	@ResponseBody
	public Map<String, Object> list(@RequestParam(defaultValue="1")Integer  page,@RequestParam(defaultValue="5")Integer  rows,@RequestParam(defaultValue="id") String sort,@RequestParam(defaultValue="asc") String order, Myo condition) throws Exception{
		
		Map<String, Object> map = new HashMap<>();
		int start = (page - 1)*rows;
		List<Myo> list = myoService.getListByCondition(start, rows, condition, sort,order);
		
		int total = myoService.getCountByCondition(condition);
		
		map.put("total", total);
		map.put("rows", list);
		
		return map;
	}
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> add(Myo myo)throws Exception{
		Map<String, Object> map = new HashMap<>();
		myoService.add(myo);
		map.put("result", true);
		return map;
	}
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> edit(Myo myo)throws Exception{
		Map<String, Object> map = new HashMap<>();
		myoService.update(myo);
		
		map.put("result", true);
		
		return map;
	}
	@RequestMapping("/view")
	@ResponseBody
	public Myo view(Integer id)throws Exception{
		return myoService.getById(id);
	}
	
	@RequestMapping("/deleteMyo")
	@ResponseBody
	public Map<String, Object> deleteMyo(Integer[] ids)throws Exception{
		myoService.deleteMyo(ids);
		Map<String, Object> map= new HashMap<>();
		map.put("result", true);
		return map;
	}
	@RequestMapping("/allMyo")
	public List<Myo> getAll()throws Exception{
		return myoService.getAll();
	}
	
}
